package com.hdugraduate;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.ImageView;
import android.widget.Toast;

public class ImageViewOne extends Activity {
	private ImageView mimageview;
	private String imagePathStatic = null;
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.vp);
		mimageview = (ImageView)findViewById(R.id.PhotoView);
		Bundle bunde = this.getIntent().getExtras();
		String photoPath = bunde.getString("imageUrl");
		imagePathStatic = photoPath;
		Bitmap bit = BitmapFactory.decodeFile(photoPath);
		mimageview.setImageBitmap(bit);
	}
	public boolean onCreateOptionsMenu(Menu menu){
		menu.add(Menu.NONE,0,0,"Uplaod");
		return super.onCreateOptionsMenu(menu);
	}
	public boolean onOptionsItemSelected(MenuItem item){
    	super.onOptionsItemSelected(item);
    	switch(item.getItemId()){
    		case 0:
    			//Intent uplaodPhoto = new Intent(ImageViewOne.this,UploadPhoto.class);
    			//Bundle bunde2 = new Bundle();
    			//bunde2.putString("imageUrl",imagePathStatic);
    			//uplaodPhoto.putExtras(bunde2);
    			//startActivity(uplaodPhoto);
    			imagePathStatic = "file:///"+imagePathStatic;
    			String tempStr = "No User";
    			File rAccountFile = new File("sdcard/TN/Account.txt");
    			try {		
    				BufferedReader br = new BufferedReader(new FileReader(rAccountFile));
    				tempStr = br.readLine();
    				br.close();
    				} catch (IOException e) {
    							// TODO Auto-generated catch block
    							e.printStackTrace();
    						}// read a line
    				
    			File rGpsFile = new File("sdcard/TN/Gps.txt");
    			String tempStr2 = "No GPS Data";
    			try {		
    				BufferedReader br = new BufferedReader(new FileReader(rGpsFile));
    				tempStr2 = br.readLine();
    				br.close();
    				} catch (IOException e) {
    							// TODO Auto-generated catch block
    							e.printStackTrace();
    						}// read a line
    			Toast.makeText(ImageViewOne.this,imagePathStatic, Toast.LENGTH_SHORT).show();
    			Intent mEmailIntent = new Intent(Intent.ACTION_SEND);
    			mEmailIntent.setType("image/jpg");
    			mEmailIntent.putExtra(Intent.EXTRA_EMAIL, new String[]{tempStr});
    			mEmailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,tempStr2);
    			mEmailIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse(imagePathStatic));
    			//mEmailIntent.putExtra(Intent.EXTRA_STREAM,imagePathStatic);
    			
    			
    			
    			startActivity(Intent.createChooser(mEmailIntent, "your Client"));
    	}
    	return true;
    }
}
